<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
	<title>阅学网</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta name="Keywords" content="">
	<meta name="description" content="">
	<jsp:include page="/user/common.jsp" />
  </head>
<body>
<jsp:include page="/user/top.jsp"></jsp:include>
<jsp:include page="/user/resourcefile/resourceLeft.jsp"></jsp:include>
<div style="float: left;width:1000px;margin-top: 8px;margin-left: 5px;">
<div style="float: right;height: 30px;background: red;margin-left:  1100px;">
	<button type="button" class="btn btn-primary" data-toggle="button" onclick="javascript:showDiv();"> 上传资源</button>
</div>
	<div>
			 	<c:if test="${empty resList  }">
			 				你还没有上传过任何资源
			 	</c:if>
				<c:forEach items="${resList}" var="res">
					 		<div style="float: left;margin-top:3px;width: 45px;height:45px">
					 			<img alt="${res.resourceTitle }" src="images/${res.fileType }.png">
					 		</div>
					 		 <div style="float: left;width:91%;margin-top:3px;margin-left: 5px;border-bottom: 1px dashed #3D8FCB;">
							 		<div style="font-size: 15px;font-weight: bold;height: 25px;">
							 			${res.resourceTitle }
							 		</div>
							 		<div style="font-size: 12px;height: 25px;">
							 			${res.resourceDescription }
							 		</div>
							 		<div style="font-size: 12px;height: 12px;">
							 			${res.commentScore }
							 		</div>
							 		<div style="font-size: 12px;height: 25px;" id="resource-div">
								 			<ul>
								 				<li>下载: ${res.downloadCount }次</li>
								 				<li>文件大小: ${res.resourceSize }</li>
								 				<li>上传时间: <fmt:formatDate value="${res.uploadDate }" type="both" pattern="yyyy-MM-dd HH:mm:ss"  /></li>
								 				<li>下载所需积分:${res.score }</li>
								 				<li>
								 						<a href="user/resource/delResource.do?id=${res.id }"><img  src="images/del.png" alt="删除" /></a>
								 						<a href="user/resource/delResource?id=${res.id }"><img  src="images/edit.png" alt="编辑" /></a>
								 				</li>
								 			</ul> 
							 		</div>
					 		</div> 
					 </c:forEach>
				</div>
	</div>
	<!-- 上传界面 -->
	<!-- 弹出框 -->
	<div id="upload-resource" class="upload-resource" style="display:none;">
		<div class="upload-resource-title">
			<span style="margin-top: -6px;float: left;">上传资源</span>
		</div>
		<div>
				<form action="user/resource/uploadResFile" method="post" enctype="multipart/form-data" id="upload-resource-form">
		 		<table>
		 				<tr>
		 						<td>资源名称:</td>
		 						<td><input type="text" value="" name="resourceTitle" class="form-control" /></td>
		 				</tr>	
		 					<tr>
		 							<td>资源类型:</td>
		 							<td>
		 									<select name="resourceType" class="form-control">
		 											<option value="1">代码</option>
		 											<option value="2">文档</option>
		 											<option value="3">工具</option>
		 											<option value="4">图书</option>
		 											<option value="5">其他</option>
		 									</select>
		 							</td>
		 					</tr>	
		 					<!-- <tr>
		 							<td>搜索关键词:</td>
		 							<td><input type="text" value="" class="form-control" name=""  /></td>
		 					</tr>	 -->
		 					<tr>
		 							<td>所属分类:</td>
		 							<td>
		 									<select name="resourceType" id="resourceType"  class="form-control">
		 									</select>
		 							</td>
		 					</tr>	
		 					<tr>
		 							<td>所需积分:</td>
		 							<td>
		 									<select name="score" id=""  class="form-control">
		 											<option>0</option>
		 											<option>1</option>
		 											<option>2</option>
		 											<option>3</option>
		 											<option>4</option>
		 											<option>5</option>
		 											<option>6</option>
		 											<option>7</option>
		 											<option>8</option>
		 											<option>9</option>
		 											<option>10</option>
		 									</select>
		 							</td>
		 					</tr>	
		 					<tr>
		 							<td>资源描述:</td>
		 							<td>
		 									<textarea rows="4" name="resourceDescription" cols="70" class="form-control"></textarea>
		 							</td>
		 					</tr>	
		 					<tr>
		 							<td>选择文件:</td>
		 							<td>
		 								 	<input type="file" name="file"/>
		 							</td>
		 					</tr>	
		 				</table>
					<div  class="upload-resource-close">
						<button type="submit" class="btn btn-primary" onclick="javascript:uploadRes(); return false;" style="margin-right: 10px;">上传</button>
						<button type="button" class="btn btn-info" onclick="javascript:hideAlertDiv()" >取消</button>
					</div>
		 		</form>
				</div>
	</div>
	<div id="upload-resource-bg" class="upload-resource-bg" style="display:none;" ></div> 	
</body>
<script type="text/javascript">
	function showDiv(){
		document.getElementById("upload-resource").style.display='block';
		document.getElementById("upload-resource-bg").style.display='block';
		$.post(
			'user/resource/listType',
			function(data){
				if(data != null){
					$('#resourceType').empty();
					for(var i=0;i<data.length;i++){
						$('#resourceType').append("<option value=\""+data[i].articleTypeName+"\">"+data[i].articleTypeName+"</option>");
			 		}
				}
			},
			'json'
		);
	}
	
	function hideAlertDiv(){
		document.getElementById("upload-resource").style.display='none';
		document.getElementById("upload-resource-bg").style.display='none';
	}
	function uploadRes(){
				var resourceTitle = $("input[name='resourceTitle']").val();
				var resourceType = $("input[name='resourceType']").val();
				var score = $("input[name='score']").val();
				var resourceDescription = $("textarea[name='resourceDescription']").val();
				var file = $("input[name='file']").val();
				if(resourceTitle == '' || resourceTitle.length >32){
					alert('标题不能为空且长度不能超过32个字!');
					return false;
				}
				if(resourceType == ''){
					alert('资源类型不能为空!');
					return  false;
				}
				if(score == ''){
					alert('下载所需分数不能为空!');
					return  false;
				}
				if(resourceDescription == '' || resourceDescription.length >500){
					alert('描述不能为空且长度不能超过500个字!');
					return  false;
				}
				if(file == ''){
					alert('你还未选择要上传的文件!');
					return  false;
				}
				document.getElementById("upload-resource-form").onsubmit();
	}
</script>
</html>
